<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        h3 {
            padding: 20px 10px;
        }

        li {
            list-style: none;
        }

        .list li {
            line-height: 45px;
            text-indent: 10px;
            border: 1px solid #333;
        }

        .list li+li {
            border-top: 0;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <h3 id="title">批量操作元素</h3>
        <div class="list">
            <li>01</li>
            <li>02</li>
            <li>03</li>
            <li>04</li>
            <li>05</li>
            <li>06</li>
        </div>
        <input type="text" class="year">
    </div>
</body>
<script>
    // 封装一个js库,可以帮助我们快速 操作元素
    // 批量操作元素  => 修改html,text,显隐,设置宽高,设置样式,类名(增删改),绑定事件



    function GetEle(selector) {
        this.eles = document.querySelectorAll(selector);
    }
    GetEle.prototype.html = function (con) {
        if (arguments.length >= 1) { //有参数(至少一个)
            for (var i = 0; i < this.eles.length; i++) {
                var ele = this.eles[i];
                ele.innerHTML = con;
            }
        } else { //没有参数
            return this.eles[0].innerHTML;
        }
    }
    GetEle.prototype.text = function (con) {
        if (arguments.length >= 1) { //有参数(至少一个)
            for (var i = 0; i < this.eles.length; i++) {
                var ele = this.eles[i];
                ele.innerText = con;
            }
        } else { //没有参数
            return this.eles[0].innerText;
        }
    }
    GetEle.prototype.val = function (con) {
        if (arguments.length >= 1) { //有参数(至少一个)
            for (var i = 0; i < this.eles.length; i++) {
                var ele = this.eles[i];
                ele.value = con;
            }
        } else { //没有参数
            return this.eles[0].value;
        }
    }

    var $listLi = new GetEle(".list li");
    console.log($listLi);
    $listLi.html(456456);

    // new GetEle(".list li").html(456456)

    var $title = new GetEle("#title");
    console.log($title);
    $title.html(123123);

    var $year = new GetEle(".year");
    console.log($year);
    $year.val(123123);


</script>

</html>